package jwanalytics.ejb.webhouse;

import java.util.Date;
import java.util.GregorianCalendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="date_dimension")
public class DateDimension {
	
	/** Id or primary key field of this class. */
	private Integer id;
	
	/** 
	 * This is just the date, not the time. 
	 * In postgres it is a date field only which is just 4 bytes instead of others which store date and time and occuppy 8 bytes. 
	 */
	private Date date;
	
	/**
	 * Will either be "Weekend" or "Non weekend". 
	 */
	private String weekendStatus;
	
	/**
	 * Will either be "" or "".
	 * @TODO: for a complete implementation you probably want to track holidays on
	 * neighboring regions, cities, province and land holidays.  Each one would need a
	 * separate column.  This column would then store whether it is a holiday on any of these
	 * regions.
	 */
	private String holidayStatus;	
	
	
	/**
	 * Holiday density index.  This is a formula to compute the density of holidays around a date. 
	 * The more holidays close by a date, the higher this index.
	 */
	private float holidayDensityIndex;
	
	
	public DateDimension() {
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="date_key")	
	public Integer getId() {
		return this.id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(name="date")		
	public Date getDate() {
		return date;
	}
	
	public void setDate(Date date) {
		this.date = date;
	}
	
	@Column(name="weekend_status")		
	public String getWeekendStatus() {
		return weekendStatus;
	}

	public void setWeekendStatus(String weekendStatus) {
		this.weekendStatus = weekendStatus;
	}
	
	@Column(name="holiday_status")
	public String getHolidayStatus() {
		return holidayStatus;
	}

	public void setHolidayStatus(String holidayStatus) {
		this.holidayStatus = holidayStatus;
	}
	
	@Column(name="holiday_density_index")
	public float getHolidayDensityIndex() {
		return holidayDensityIndex;
	}

	public void setHolidayDensityIndex(float holidayDensityIndex) {
		this.holidayDensityIndex = holidayDensityIndex;
	}
	
	
	public int hashCode() {
		return (this.id == null) ? 0 : this.id.hashCode();
	}

	public boolean equals(Object object) {
		if (object instanceof DateDimension) {
			final DateDimension obj = (DateDimension) object;
			return (this.id != null) ? this.id.equals(obj.id) : (obj.id == null);
		}
		return false;
	}
		
	
	/** Obtains a data instantiated for the moment this method is called. */
	public static Date getNow() {
		//Some pre-calculations on day and time for page hit.
		GregorianCalendar nowCalendar = new GregorianCalendar();
		return nowCalendar.getTime(); //time when page was hit.		
	}
	
}
